<?php

namespace app\controller\bossManager;

use app\service\UrlDomainRelationService;
use app\validate\UrlSelectorValidate;
use app\service\UrlSelectorService;
use app\service\UrlService;

class UrlSelectorController extends WebBossController
{
    public function initValidate()
    {
        $this->validate = new UrlSelectorValidate();
    }

    public function info_action()
    {
        $data = UrlDomainRelationService::getRelationBySelector();
        return self::ok($data);
    }


    public function del_action()
    {
        $input = $this->check();
        $res = UrlDomainRelationService::delBySelector($input['id']);
        return self::ok($res);
    }

    public function alloc_action()
    {
        $input = $this->check();
        foreach ($input['selector'] as $selector) {
            $this->check('selectorItem', $selector);
        }
        $data = UrlDomainRelationService::allocBySelector($input);
        return self::ok($data);
    }

    public function check_relation_action()
    {
        $input = $this->check();
        $ip = $input['ip'];
        $vendor = isset($input['vendor']) ? $input['vendor'] : '';
        $package = isset($input['package']) ? $input['package'] : '';
        $version = isset($input['version']) ? $input['version'] : '';
        $clientType = isset($input['clientType']) ? $input['clientType'] : '';
        $client = isset($input['client']) ? $input['client'] : '';
        $did = isset($input['did']) ? $input['did'] : '';
        $data = UrlService::getUrlInfoByFilter($ip, $vendor, $package, $version, $clientType, $client, $did);
        return self::ok($data);
    }
}
